<template>
  <div>
    <el-breadcrumb separator-icon="ArrowRight" style="margin: 16px">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>我的宿舍</el-breadcrumb-item>
     </el-breadcrumb>
     <el-card style="margin: 15px; min-height: calc(100vh - 111px)">
        <el-descriptions title="宿舍信息">
            <el-descriptions-item label="楼栋号">{{this.room.ldId}}</el-descriptions-item>
            <el-descriptions-item label="房间号">{{this.room.roomId}}</el-descriptions-item>
            <el-descriptions-item label="床位数">{{this.room.roomMaxpeople}}</el-descriptions-item>
            <el-descriptions-item label="入住人数">{{this.room.roomRealpeople}}</el-descriptions-item>
            <el-descriptions-item label="宿舍评分">{{this.room.score}}</el-descriptions-item>
        </el-descriptions>
        <p style="font-weight: bold;">我的室友</p>
        <div  v-for="(item,index) in stulist" :key = "item.stuId">
            <p>室友{{ index+1 }}</p>
            <el-descriptions title="">
                <el-descriptions-item label="学号">{{item.stuId}}</el-descriptions-item>
                <el-descriptions-item label="姓名">{{item.stuName}}</el-descriptions-item>
                <el-descriptions-item label="手机号">{{item.stuPhone}}</el-descriptions-item>
            </el-descriptions>
      </div>
    </el-card>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
    name:"myroominfo",
    data() {
        return {
            room:{
                ldId:null,
                roomId:null,
                roomMaxpeople:null,
                roomRealpeople:null,
                score:null
            },
            stulist:[{
                    stuId:null,
                    stuName:'',
                    stuPhone:''
            }]
        }
    },
    created(){
        this.getRoomInfo()
        this.getRoomMate()
    },
    methods:{
        async getRoomInfo(){
            var ldid = JSON.parse(window.localStorage.getItem('user')).ldId;
            ldid = parseInt(ldid)
            var roomid =  JSON.parse(window.localStorage.getItem('user')).roomId;
            roomid = parseInt(roomid)
            request.get("/sturoom/info",{ 
                 params: {
                   ldId:ldid,
                   roomId:roomid
                }}).then(res=>{
                    if(res.code==="1"){
                        this.room = res.data;
                    }
                    else{
                        this.$message({
                        type:'error',
                        message:'获取宿舍信息失败'
                        })
                    }
            })
        },
        async getRoomMate(){
            var ldid = JSON.parse(window.localStorage.getItem('user')).ldId;
            ldid = parseInt(ldid)
            var roomid =  JSON.parse(window.localStorage.getItem('user')).roomId;
            roomid = parseInt(roomid)
            var stuid =  JSON.parse(window.localStorage.getItem('user')).stuId;
            stuid = parseInt(stuid)
            request.get("/student/info",{ 
                 params: {
                   ldId:ldid,
                   roomId:roomid,
                   stuId:stuid
                }}).then(res=>{
                    if(res.code==="1"){
                        console.log(res.data)
                        this.stulist = res.data;
                    }
                    else{
                        this.$message({
                        type:'error',
                        message:'获取室友信息失败'
                        })
                    }
            })
        }

    }
}
</script>

<style>

</style>